package br.com.LeitorLog.controladores;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import br.com.LeitorLog.basicas.Item;

/**
 * ControladorUtil
 *
 * @since 05/03/2013 17:34:12
 */
public class ControladorUtil {
	private ControladorItem contItem = new ControladorItem();
	
	public ArrayList<Item> processarArquivoItens(String path) {
		
		try{
			  // Open the file that is the first 
			  // command line parameter
			  FileInputStream fstream = new FileInputStream(path);
			  // Get the object of DataInputStream
			  DataInputStream in = new DataInputStream(fstream);			  
			  BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
			  String strLine;
			  
			  //Read File Line By Line
			  while ((strLine = br.readLine()) != null)   {
				  if (!strLine.equals("")) {
					 // textoFormatado = textoFormatado + "\n" + strLine;
					  
					  contItem.processarLinha(strLine.trim());
				  }
				  
			  }
			  //Close the input stream
			  in.close();
			  
			  } catch (Exception e){//Catch exception if any
				  System.err.println("Error: " + e.getMessage());
		}
		
		return contItem.buscarListaItens();
	}
}
